<?php

function buildMenu($label)
{
	$menu = Menu::model()->getMenu($label);
	
	$result = array();
	foreach ($menu as $m)
	{
		if ($m['active'])
		{
			$result[] = buildSubMenu($m);
		}
	}

	return $result;
}

function buildSubMenu($m)
{
	$item = array();
	$item['label'] = $m['title_'.Yii::app()->language];
	if (!empty($m['route']))
	{
		$item['url'] = Yii::app()->createAbsoluteUrl($m['route']);
	}
	if (isset($m['items']))
	{
		foreach ($m['items'] as $subitem)
		{
			$item['items'][] = buildSubMenu($subitem);
		}
	}
	return $item;
}